﻿#region 命名空间

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;
using System.Web;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL.CacheHepler
{
    public static class RewriterCache
    {
        private static Rules _regexList;
        private static readonly object Objlockhelper = new object();

        public static Rules ReadRewriterRule(HttpContext context)
        {
            if (_regexList == null)
            {
                lock (Objlockhelper)
                {
                    if (_regexList == null)
                    {
                        _regexList =
                            SerializableHelper.DeSerialize<Rules>(
                                new FileInfo(context.Server.MapPath("~/Config/WinnerCMS.UrlRewriter.config")));

                        foreach (var v in _regexList.Datas)
                        {
                            //预制正则表达式
                            v.NewPathRegex = new Regex(v.NewPath, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                        }
                    }
                }
                if (_regexList == null)
                    return new Rules();
            }

            return _regexList;
        }
    }
}